<?php

class UserAgreementsController extends AppController {

    var $name = 'UserAgreements';
    var $uses = array();
    var $components = array('Email');

    function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->allowedActions = array('*');
    }

    function index($id=null) {
        $this->layout = "cms";
        $this->loadModel('Category');
        $this->set('item', $this->Category->categoryArray());
        $this->loadModel('Cmspage');
        $this->set('cmspages', $this->Cmspage->find('all', array('conditions' =>
                    array('Cmspage.listed_under' => 'User Agreement', 'Cmspage.status' => 'Enabled'), 'order' => 'Cmspage.id ASC'
                )));

        if ($id != null) {
            $this->set('cmspage_dtls', $this->Cmspage->find('all', array('conditions' =>
                        array('Cmspage.listed_under' => 'User Agreement', 'Cmspage.status' => 'Enabled', 'Cmspage.id' => $id)
                    )));
        } else {
            $this->set('cmspage_dtls', $this->Cmspage->find('all', array('conditions' =>
                        array('Cmspage.listed_under' => 'User Agreement', 'Cmspage.status' => 'Enabled'), 'order' => 'Cmspage.id ASC', 'limit' => 1
                    )));
        }
    }

    function feedback() {
        $this->layout = null;
        $this->loadModel('Category');
        $this->set('item', $this->Category->categoryArray());
        $this->loadModel('Cmspage');
        $this->set('cmspages', $this->Cmspage->find('all', array('conditions' =>
                    array('Cmspage.listed_under' => 'User Agreement', 'Cmspage.status' => 'Enabled'), 'order' => 'Cmspage.id ASC'
                )));
        if (!empty($_POST['name'])) {

            $contactemail = $this->Contact->findById("1");
            ////////for send email////////
            $this->Email->to = $contactemail['Contact']['email'];
            //$this->Email->bcc = array('secret@example.com');
            $this->Email->subject = 'Feedback from Authentic Avenue.';
            //$this->Email->replyTo = 'noreply@authenticavenue.com';
            $this->Email->from = $_POST['name'] . '<' . $_POST['email'] . '>';
            $this->Email->template = 'feedback'; // note no '.ctp'
            //Send as 'html', 'text' or 'both' (default is 'text')
            $this->Email->sendAs = 'html'; // because we like to send pretty mail
            //Set view variables as normal
            $this->set('formdata', $_POST);
            //$this->set('password', $rand);
            //Do not pass any args to send()
            $this->Email->send();
            //////////////////////////////
            $this->render('success');
        }
    }

}

?>